<template>
  <div>
    <div class="clearfix">
      <div class="leftTop">
        <!-- <div class="letTopTitle" style="color: #545c75">轮播图列表/</div> -->
        <el-button type="primary" @click="addBannerPci" plain size="mini"
          > <img src="../../../assets/images/addess.png" style="width:10px;height:10px" alt=""> 添加轮播图</el-button
        >
      </div>
      <div style="clear: both"></div>
      <el-table
        :data="tableData"
        stripe
        style="width: 100%; overflow-x: auto !important"
      >
        <el-table-column prop="date" label="序号" width="80"> </el-table-column>
        <el-table-column prop="name" label="轮播图名称" width="220">
        </el-table-column>
        <el-table-column prop="address" label="指向" width="260">
        </el-table-column>
        <el-table-column prop="address" label="当前状态" width="220">
        </el-table-column>
        <el-table-column prop="address" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="enable(scope.row)"
              >启用</el-button
            >
            <el-button type="text" @click="set(scope.row)">修改</el-button>
            <el-button type="text" size="small" @click="del(scope.row)"
              >删除</el-button
            >
            <el-button type="text" size="small" @click="top(scope.row)"
              >上移</el-button
            >
            <el-button type="text" size="small" @click="bot(scope.row)"
              >下移</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 添加轮播图的弹框 -->
    <el-dialog
      title="添加轮播图"
      :visible.sync="dialogVisible"
      width="405px"
      :before-close="handleClose"
    >
      <div class="bannerInfoListBox">
        <div class="bannerInfoList" style="margin-bottom: 10px">
          <div class="title">* 轮播图标题：</div>
          <el-input
            v-model="input"
            class="bannerTitleInput"
            placeholder="请输入内容"
          ></el-input>
        </div>
        <div class="uoLoadPic">
          <div class="title">* 上传图片：</div>
          <div style="text-align: center">
            <el-upload
              :action="httpurl + '/api/fileUpload'"
              list-type="picture-card"
              :before-upload="beforeAvatarUpload"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
              :class="{ hide: hideUploads }"
              :on-change="picChange"
            >
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog
              :visible.sync="dialogVisiblePic"
              append-to-body
              style="z-index: 99999 !important"
            >
              <img width="100%" :src="dialogImageUrl" alt="" />
            </el-dialog>
          </div>
          <div class="titleInfo">
            <span>大小：345x150px</span>
            <span>图片大小建议不超过1M</span>
          </div>
        </div>
        <el-radio-group
          v-model="tabPosition"
          style="margin-bottom: 30px; width: 100% !important"
          @change="histTypeUpdate"
        >
          <el-radio-button label="one">跳转至图片</el-radio-button>
          <el-radio-button label="two">站内跳转</el-radio-button>
          <el-radio-button label="three">站外跳转</el-radio-button>
        </el-radio-group>
        <div
          class="botUploadPic"
          v-if="tabPosition == 'one'"
          style="text-align: center"
        >
          <el-upload
            :action="httpurl + '/api/fileUpload'"
            list-type="picture-card"
            :file-list="data.jumpPhotos"
            :on-preview="handlePictureCardPreview1"
            :on-remove="handleRemove1"
            :class="{ hide: hideUpload }"
            :on-change="picChange1"
            :on-success="handleSuccess1"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible1">
            <img width="100%" :src="dialogImageUrl" alt="" />
          </el-dialog>
        </div>
        <div class="botUploadPic" v-if="tabPosition == 'two'">
          <div class="box">
            <div
              class="funcList"
              v-for="(item, index) in options"
              :key="item.jumpAddress"
              :class="selectAds == index ? 'selectActive' : ''"
              @click="selectListActive(item, index)"
            >
              {{ item.name }}
              <i
                class="el-icon-check"
                style="color: blue"
                type="primary"
                v-show="selectAds == index"
              ></i>
            </div>
          </div>
        </div>
        <div class="botUploadPic" v-if="tabPosition == 'three'">
          <el-input
            v-model="input"
            
            class="outsideUrl"
            placeholder="https://www."
          ></el-input>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sure"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import { isUrl } from "../../../assets/js/commion"
export default {
  data() {
    return {
      hideUpload: false, //控制上传图片按钮是否显示
      hideUploads: false,
      selectAds: 0, //选中的地址
      // 图片链接地址
      httpurl: this.GLOBAL.httpurl,
      dialogImageUrl: "",
      dialogVisible: false,
      // 控制显示查看的图片
      dialogVisiblePic: false,
      tabPosition: "one",
      options: null,
      data: {
        jumpPhotos: [],
      },
    };
  },
  created() {
    this.geUrlList();
  },
  methods: {
    // 上传图片发生变化
    picChange1(file, fileList) {
      this.hideUpload = fileList.length >= 1;
    },
    // 点击确定
    sure(){
      alert(isUrl("https://www.baidu.com/"))
      this.dialogVisible = false
    },
    picChange(file, fileList) {
      this.hideUploads = fileList.length >= 1;
    },
    // 上传成功图片
    handleSuccess1(res, file, fileList) {
      console.log(res.data.filePath);
      this.data.jumpPhotos.push({
        url: res.data.filePath,
      });
    },
    // 点击添加轮播图
    addBannerPci() {
      this.dialogVisible = true;
    },
    // 获取站内跳转的列表
    geUrlList() {
      axios
        .post("/api/template/queryInternalJump", {})
        .then((res) => {
          this.options = res.data.data;
          console.log(this.options);
          console.log("chenggoing");
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 站内跳转选中
    selectListActive(val, index) {
      console.log(val);
      console.log(index);
      this.selectAds = index;
    },
    beforeAvatarUpload(file) {
      const isJPG =
        file.type === "image/jpeg" ||
        file.type === "image/png" ||
        file.type === "image/jpg";
      if (!isJPG) {
        this.$message.error("只能上传图片");
      }
      const isSize = new Promise((resolve, reject) => {
        const width = 345;
        const height = 140;
        const _URL = window.URL || window.webkitURL;
        const img = new Image();
        img.onload = () => {
          const valid = img.width == width && img.height == height;
          valid ? resolve() : reject();
        };
        img.src = _URL.createObjectURL(file);
      }).then(
        () => {
          return file;
        },
        () => {
          layer.open({
            content: "图片尺寸限制为345 x 150",
            skin: "msg",
            time: 2, //1秒后自动关闭
          });
          // this.$notify({title: "错误",message: ,type: "error"});
          return Promise.reject();
        }
      );
      return isJPG && isSize;
    },
    histTypeUpdate(val) {
      console.log(val);
    },
    // 上传图片的
    handleRemove(file, fileList) {
      console.log(file, fileList);
      this.hideUploads = fileList.length >= 1;
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisiblePic = true;
    },
    handleRemove1(file, fileList) {
      console.log(file, fileList);
      this.data.jumpPhotos = [];
      this.hideUpload = fileList.length >= 1;
    },
    handlePictureCardPreview1(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisiblePic = true;
    },
    //点击切换
    handleClick(tab, event) {
      console.log(tab);
    },
  },
};
</script>

<style scoped>
/deep/ .el-upload-list__item {
  transition: none !important;
}
.selectActive {
  background: #f5f7fa;
}
.bannerInfoList {
  display: flex;
  align-items: center;
}
/deep/ .el-upload-list__item {
  width: 100%;
}
/deep/ .el-upload--picture-card {
  width: 100%;
  border: 0;
  background: #f9fafc;
}
.titleInfo {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
}
/deep/ .el-upload--picture-card i {
  color: #409eff;
}
/deep/ .outsideUrl {
  width: 365px;
}
/deep/ .outsideUrl .el-input__inner {
  width: 100% !important;
}
/deep/ .el-radio-button__inner {
  width: 100% !important;
}
/deep/ .el-radio-button {
  width: 33.333% !important;
}
/deep/ .bannerTitleInput {
  width: 250px !important;
}
/deep/ .bannerTitleInput .el-input__inner {
  width: 100% !important;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.box {
  height: 180px;
  overflow-y: auto;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
}
.box > div {
  padding: 0 10px;
}
.funcList {
  cursor: pointer;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* 下面先不知道干嘛 */
.titles {
  font-weight: bold;
  text-align: center;
  padding: 10px 0;
  width: 100%;
}
.cont {
  background: rgb(246, 246, 246);
  height: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  margin: 0 auto;
  padding-top: 10px;
}
.phoneBannere {
  background: #ccc;
  height: 150px;
  margin-bottom: 10px;
}
.moneys {
  margin: 4px 0;
}
.yuan {
  font-size: 22px;
  font-weight: 600;
  color: rgb(238, 96, 88);
}
.first {
  display: inline-block;
  margin-right: 20px;
}
.profit {
  background: white;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 8px;
}
.phoneMenu {
  background: white;
  margin-top: 20px;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 8px;
  margin-bottom: 20px;
}
.subList {
  width: 60px;
  height: 60px;
  margin-bottom: 20px;
}
.menuList {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.pic {
  width: 50px;
  height: 50px;
  background: red;
  border-radius: 50%;
  margin: 0 auto;
}
.picTitle {
  text-align: center;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.leftTop {
  display: flex;
  justify-content: space-between;
  margin-top: 15px;
  margin-bottom: 15px;
  box-sizing: border-box;
  padding: 0 20px;
}
.clearfix:after {
  display: block;
  height: 0;
  clear: both;
  content: ".";
  visibility: hidden;
}
</style>
<style>
.hide .el-upload--picture-card {
  display: none;
}
</style>